package com.ztspeech.vad;


public class FrameVoiceDetector {
	public static final int SAMPLE_RATE = 16000;
	public static final int FRAME_LEN_MS = 10;
	
	private long hVad = 0;
	
	public FrameVoiceDetector(int mode) {
		hVad = VadJni.newVad(SAMPLE_RATE, FRAME_LEN_MS, mode);
	}
	
	@Override
	protected void finalize() throws Throwable {
		if (hVad != 0)
			VadJni.delVad(hVad);
		
		super.finalize();
	}

	public boolean reset() {
		return VadJni.resetVad(hVad);
	}
	
	public boolean restart() {
		return VadJni.restartVad(hVad);
	}
	
	public int setParam(int param, int val) {
		return VadJni.setIntParam(hVad, param, val);
	}
	
	public int setParam(int param, float val) {
		return VadJni.setFloatParam(hVad, param, val);
	}
	
	public boolean inputWave(byte[] waveData, int offset, int frameNum, boolean isEnd) {
		return VadJni.inputWave(hVad, waveData, offset, frameNum, isEnd);
	}
	
	public boolean inputFloatWave(float[] waveData, int offset, int frameNum, boolean isEnd) {
		return VadJni.inputFloatWave(hVad, waveData, offset, frameNum, isEnd);
	}
	
	public int getMaxFrame() {
		return VadJni.getMaxFrame(hVad);
	}
	
	public float getFrameProb(int frame, int dim) {
		return VadJni.getFrameProb(hVad, frame, dim);
	}
	
}
